<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>账户安全</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../css/element.css">
    <!-- 必须先引入vue，  后使用element-ui -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script>
    <!-- 引入element 的组件库-->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<!--    bootstrap的css以及js还有组件库-->
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
    <style>
        body{
            background-color: #F4F6FA;
        }
        .sercuity{
            margin: 20px;
            background-color: white;
        }
        .sercuity-title{
            font-size: 20px;
            height: 50px;
            width: 100%;
            background-color: white;
            padding-top: 15px;
            padding-left: 20px;
        }
        .sercuity-body{
            width: 100%;
            margin: 20px;
        }
        .sercuity-body-pwd{
            font-weight: bold;
            margin-top: 10px;
        }
        .sercuity-body-input{
            margin-top: 10px;
            border-radius: 5px;
            width: 96%;
            height: 40px;
            border-color: #F4F6FA;
        }
        .sercuity-body-btn{
            margin-top: 20px;
            margin-left: 46%;
            background-color: #26BABD;
            color: white;
            width: 100px;
            height: 50px;
            text-align: center;
            border-radius: 5px;
            margin-bottom: 50px;
        }
    </style>
</head>
<body>
    <div id="account">
        <div class="sercuity">
            <div class="sercuity-title">账户安全</div>
            <hr>
            <div class="sercuity-body">
                <form>
                    <input type="hidden" name="uid">
                    <div class="sercuity-body-pwd">
                        旧密码
                    </div>
                    <div>
                        <input type="password" name="password" v-model="password" class="sercuity-body-input" placeholder="请输入原始密码" id="oldPwd">
                    </div>
                    <div class="sercuity-body-pwd">
                        新密码
                    </div>
                    <div>
                        <input type="password" name="" v-model="newPassword" class="sercuity-body-input pwd" placeholder="请输入新的密码" id="newPwd">
                        <i class="lock icon"></i>
                    </div>
                    <div class="sercuity-body-pwd">
                        确认新密码
                    </div>
                    <div>
                        <input type="password" class="sercuity-body-input repwd" id="newPwd1" placeholder="请确认新的密码">
                        <i class="lock icon"></i>
                    </div>
                    <div><button @click="updPwd(password,newPassword)" class="sercuity-body-btn">修改密码</button></div>
                </form>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript" src="../Semantic-UI/semantic.js"></script>
<script>
    let account=new Vue({
        el: '#account',
        name: 'accountSecurity',
        data(){
            return{
                pwd: {},
                password: '',
                newPassword: ''
            };
        },
        methods: {
            updPwd(password,newPassword){
                var msg = "您真的确定要修改吗？\n\n请确认！";
                if (confirm(msg)==true) {
                let pwd=$("#newPwd").val();
                let pwd1=$("#newPwd1").val();
                let oldPwd=$("#oldPwd").val();
                if (pwd==" " || pwd==null || pwd1=="" || pwd1==null || oldPwd=="" || oldPwd==null){
                    alert("原始密码以及新密码不能为空");
                    return false;
                }else if(pwd==oldPwd || pwd1==oldPwd){
                    alert("新密码不能与原密码一致");
                    return false;
                }else if (pwd!=pwd1){
                    alert("两次密码不一致");
                    return false;
                }else{
                    this.password=password;
                    this.newPassword=newPassword;
                    axios.post('/updatePwd?oldPwd='+password+"&password="+newPassword).then(res=>{

                    })
                    alert("修改成功！！！");
                    parent.location.href="/logout";
                    return true;
                }
                }else{
                        alert("修改失败！！！");
                        window.location.href="accountSecurity.html";
                        return false;
                    }

                }
            }

    })
</script>
</html>